//
//  ZPRightImageButton.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/7.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "ZPRightImageButton.h"

@interface ZPRightImageButton()

@property (strong, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) UILabel *titleLabel;

@end

@implementation ZPRightImageButton

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title titleFont:(UIFont *)font titleColor:(UIColor *)titleColor image:(UIImage *)image buttonBackgroundColor:(UIColor *)backgroundColor
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = backgroundColor;
        
        // 初始化视图
        if (!self.titleLabel) {
            self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width - 20, frame.size.height)];
            self.titleLabel.text = title;
            self.titleLabel.textColor = titleColor;
            self.titleLabel.font = font;
            self.titleLabel.textAlignment = NSTextAlignmentCenter;
            [self addSubview:self.titleLabel];
        }
        
        if (!self.imageView) {
            self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width - 20, 0, 20, frame.size.height)];
            self.imageView.image = image;
            self.imageView.contentMode = UIViewContentModeCenter;
            [self addSubview:self.imageView];
        }
        
    }
    return self;
}

- (void)changeTitle:(NSString *)title{
    self.titleLabel.text = title;
}

@end
